<template>
    <el-container>
        <el-aside width="235px">
            <el-menu default-active="2" class="el-menu-vertical-demo" style="border:0;" @select="handleSelectInSonBar">
                <span v-for="item in navArr" :key="item.id">
                    <el-submenu :index="item.id" v-if="item.hasSon">
                        <template slot="title">
                            <div style="width:100%;height:100%;display: flex;align-items: center;">
                                <i class="el-icon-location"></i>
                                <span>{{ item.content }}</span>
                            </div>
                        </template>
                        <el-menu-item-group v-for="sonItem in item.sonNavs" :key="sonItem.id">
                            <el-menu-item :index="sonItem.id" style="display:flex;">{{ sonItem.content }}</el-menu-item>
                        </el-menu-item-group>
                    </el-submenu>
                    <el-menu-item :index="item.id" v-else style="display: flex;align-items: center;">
                        <i class="el-icon-menu"></i>
                        <span slot="title">{{ item.content }}</span>
                    </el-menu-item>
                </span>
            </el-menu>
        </el-aside>
        <el-main>
            <div style="height:100%;"><router-view :key="$route.fullPath"></router-view></div>
        </el-main>
    </el-container>
</template>

<script>
import request from "../axios/request";
export default {
    props: ["currentTab"],
    data() {
        return {
            navArr: [],
        }
    },
    methods: {
        handleSelectInSonBar(index) {
            let name = null
            let content = null
            console.log(index);
            switch (index) {
                case '18':
                case '20':
                    name = 'GetSoftWareCode'
                    content = index
                    break;
                case '19':
                    name = 'ApplyForTest'
                    break;
                case '21':
                    name = 'UserManage'
                    break;
                case '25':
                    name = 'ParameterUnit'
                    break;
                default:
                    name = 'TableDataCom'
                    content = index
                    break;
            }
            this.$router.push({
                name: name,
                params: {
                    content: content,
                },
            });
        },
        async updateNav(index) {
            let resOfGettingNavBtn = await request({
                url: "/sys/api/Nav/getNavBtn/" + index,
                method: "GET",
            });
            this.navArr = resOfGettingNavBtn.data.data
        }
    },
    watch: {
        async currentTab(val) {
            this.updateNav(val)
        },
    },
    beforeMount() {
        this.updateNav("1")
    }
}
</script>

<style scoped>
.el-aside {
    color: #333;
    text-align: center;
    line-height: 200px;
}

.el-main {
    background-color: #E9EEF3;
    color: #333;
    text-align: center;
    padding: 10px;
}
</style>